import json

import requests

#发送请求
#url
#登录
ip = "http://192.168.68.133:8080"
loginData = {"username":"admin","password":"123456"}
r=requests.post(f"{ip}/login",data=loginData)
print(r)
print(r.json())
#获取token
token=r.json()['Admin-Token']

#接口请求，传值
#get ，url后面 传给params
#post x-www-form 传给data
#     form-data 普通传给data    特殊传给files
#     json       传给json


#文件上传
fData1={'type':'img'}
fname=r'D:\2504\apiTest\datas\1.png'
fData2={'file':
            ('1.png',
                open(fname,'rb'),
                'image/png'
             )
        }
r2=requests.post(f"{ip}/file/upload",data=fData1,files=fData2,headers={'Admin-Token':token})
print(r2)
print(r2.json())
#获取batchId
ebatchId=r2.json()['batchId']


#增加log日志
addLogData={"categoryId":"1","content":"1","tomorrow":"2","question":"3","batchId":ebatchId,"sendUserIds":"","sendDeptIds":"","customerIds":"","contactsIds":"","businessIds":"","contractIds":""}
r3=requests.post(f"{ip}/OaLog/addOrUpdate",json=addLogData,headers={'Admin-Token':token})
print(r3)
print(r3.json())


#查看log日志
getLogData={'page':1,'limit':5,'by':1}
r1=requests.post(f"{ip}/OaLog/queryList",json=getLogData,headers={'Admin-Token':token})
print(r1)
print(r1.json())
#获取logId
eId=r1.json()['data']['list'][0]['logId']
print(eId)

#修改log日志
upLogData={"logId":eId,"categoryId":"1","content":"好123","tomorrow":"很好456","question":"非常好789","batchId":ebatchId,"sendUserIds":"","sendDeptIds":"","customerIds":"","contactsIds":"","businessIds":"","contractIds":""}
r4=requests.post(f"{ip}/OaLog/addOrUpdate",json=upLogData,headers={'Admin-Token':token})
print(r4)
print(r4.json())


#删除log日志
delLogData={"logId":eId}
r5=requests.post(f"{ip}/OaLog/deleteById",data=delLogData,headers={'Admin-Token':token})
print(r5)
print(r5.json())


# if __name__=='__main__':
#     header={'Admin-Token':'token'}
#     # print(header,type(header))
#     # #字典转json格式的字符串
#     # l=json.dumps(header)
#     # print(l,type(l))
#     # #字符串转json格式的字典
#     # dd=json.loads(l)
#     # print(l,type(dd))
#
#     #json格式的字符串转字典
#     #字典转json格式的文件
#     fname=r'D:\2504\apiTest\datas\myjson.json'
#     f=open(fname,'w')
#     json.dump(header,f)
#
#     #json格式的文件转字典
#     fname=r'D:\2504\apiTest\datas\myjson.json'
#     f=open(fname,'r')
#     ss=json.load(f)
#     print(ss,type(ss))
